
using System;
using Mono.Unix;
using Habazie.kf2.Core;
using Habazie.kf2.Events;

namespace Habazie.kf2.GUI
{
	
	
	public class EventButton : Gtk.Button
	{
		///<summary>Event box</summary>
		private EventBox m_box;
		
		private Gtk.Image m_image;
		
		private Gtk.Tooltips m_tooltips;
		
		public EventButton(EventBox box) : base ()
		{
			m_image = new Gtk.Image ();
			m_image.Show ();
			this.Add (m_image);
			this.Relief = Gtk.ReliefStyle.None;
			
			this.Clicked += OnClicked;
			
			m_tooltips = new Gtk.Tooltips ();
			
			m_box = box;
			m_box.Updated += OnUpdated;
			
			OnUpdated (this, null);
		}
		
		protected virtual void OnClicked (object o, EventArgs args)
		{
			Event e = m_box.Peek ();
			if (e != null) {
				m_box.Process (e.Id);
			}			
		}
		
		protected virtual void OnUpdated (object o, EventArgs args)
		{
			Event e = m_box.Peek ();
			if (e != null) {
				m_image.Pixbuf = Gdk.Pixbuf.LoadFromResource ("pix_message.png");
				this.Sensitive = true;
				m_tooltips.SetTip (this, String.Format (
						Catalog.GetPluralString ("One event in queue", "{0} events in queue", m_box.Count),
					m_box.Count), null);
			} else {
				m_image.Pixbuf = null;
				this.Sensitive = false;
			}
		}
		
		
	}
}
